﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MySql.Data.MySqlClient;
using LdExpress;
using System.IO;

public partial class _Default : System.Web.UI.Page
{
    public string ContainerPage = "./ProcessDescription.aspx";
    public string strCondition = "";
    public string strPager = "";
    public string strError = "";
    public string strMess = "";
    public string type = "";
    public int nPermissions = 0;
    public string strProcessName = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["logined_id"] != null)
        {

            if (Request.QueryString["type"] != null)
                type = Request.QueryString["type"].ToString();
            else
                type = "0";
            switch (type)
            {
                case "1":
                    strProcessName = "QUY TRÌNH CUS";
                    nPermissions = int.Parse(Session["ProcessCus"].ToString());
                    break;
                case "2":
                    strProcessName = "QUY TRÌNH DOC";
                    nPermissions = int.Parse(Session["ProcessDoc"].ToString());
                    break;
                case "31":
                    strProcessName = "QUY TRÌNH SALES GĐ1";
                    nPermissions = int.Parse(Session["ProcessSalesGD1"].ToString());
                    break;
                case "32":
                    strProcessName = "QUY TRÌNH SALES GĐ2";
                    nPermissions = int.Parse(Session["ProcessSalesGD2"].ToString());
                    break;
                case "3":
                    strProcessName = "QUY TRÌNH SALES GĐ3";
                    nPermissions = int.Parse(Session["ProcessSalesGD3"].ToString());
                    break;
                case "4":
                    strProcessName = "QUY TRÌNH ACCNT";
                    nPermissions = int.Parse(Session["ProcessAccnt"].ToString());
                    break;
                case "5":
                    strProcessName = "NỘI QUY CÔNG TY";
                    nPermissions = int.Parse(Session["processregulation"].ToString());
                    break;
                case "6":
                    strProcessName = "CHỌN HỒ SƠ";
                    nPermissions = int.Parse(Session["ProcessChooseProfile"].ToString());
                    break;
                case "7":
                    strProcessName = "YÊU CẦU TUYỂN DỤNG";
                    nPermissions = int.Parse(Session["ProcessRecruitmentRequirements"].ToString());
                    break;
                case "8":
                    strProcessName = "PRICING";//"VĂN HÓA";
                    nPermissions = int.Parse(Session["ProcessFreightGuide"].ToString());
                    break;
                case "9":
                    strProcessName = "OPERATION";//"GIÁ TRỊ";
                    nPermissions = int.Parse(Session["ProcessTruckingGuide"].ToString());
                    break;
                case "10":
                    strProcessName = "TUYỂN SALES";
                    nPermissions = int.Parse(Session["ProcessSalesRecruitment"].ToString());
                    break;
                case "11":
                    strProcessName = "TUYỂN DOC";
                    nPermissions = int.Parse(Session["ProcessDocRecruitment"].ToString());
                    break;
                case "12":
                    strProcessName = "TUYỂN KẾ TOÁN";
                    nPermissions = int.Parse(Session["ProcessAccountingRecruitment"].ToString());
                    break;
                case "13":
                    strProcessName = "TEST SALES";
                    nPermissions = int.Parse(Session["ProcessTestSales"].ToString());
                    break;
                case "14":
                    strProcessName = "TEST DOC";
                    nPermissions = int.Parse(Session["ProcessTestDoc"].ToString());
                    break;
                case "15":
                    strProcessName = "TEST KẾ TOÁN";
                    nPermissions = int.Parse(Session["ProcessTestAccounting"].ToString());
                    break;
            }
            if (Session["superadmin"] != null && int.Parse(Session["superadmin"].ToString()) > 0) nPermissions = 10;
            if (nPermissions <= 0) Response.Redirect("Login.aspx");
        }
        else
            Response.Redirect("Login.aspx");
        if (!Page.IsPostBack)
        {
            LoadProcessDescriptionContent();
            if (nPermissions < 3)
            {
                btnSave.Visible = false;
                btnShowHide.Visible = false;
            }
        }

    }
    protected void LoadProcessDescriptionContent()
    {
        if (Request.QueryString["type"] != null)
        {
            ProcessDescription obj = new ProcessDescription();
            int lType = int.Parse(Request.QueryString["type"].ToString());
            if (lType > 0)
            {
                obj.Load(lType, GV.cn, GV.trans);
                txtProcessDescriptions.Text = obj.Description;
                lblDisplay.Text = obj.Description;
            }
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (Request.QueryString["type"] != null)
        {
            long userID = long.Parse(Session["logined_id"].ToString());
            ProcessDescription obj = new ProcessDescription();
            int lType = int.Parse(Request.QueryString["type"].ToString());
            if (lType > 0)
            {
                obj.Load(lType, GV.cn, GV.trans);
            }
            obj.Type = lType;
            obj.UserID = userID;
            obj.Description = txtProcessDescriptions.Text;
            obj.Save(GV.cn, GV.trans);
            lblDisplay.Text = txtProcessDescriptions.Text;
        }
    }
}
